package com.aabte.design2.behavioral.chain.v2;

import com.aabte.design2.behavioral.chain.Request;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
public class FilterChain implements Chain {

    private Iterator<Filter> filterIterator;

    public FilterChain(Collection<Filter> filters) {
        this.filterIterator = filters.iterator();
    }

    @Override
    public void doFilter(Request request) {
        if (filterIterator.hasNext()) {
            filterIterator.next().doFilter(request, this);
        }
    }
}
